1. Field of the Invention
The present invention relates to an improved data processing system and, in particular, to a method and system for using a database. Still more particularly, the present invention provides a method and system for using an object-oriented software program.
2. Description of Related Art
In an object-oriented application, the relationships and behavior among objects are defined in accordance with an object model. Depending upon the use of the objects and the desired level of persistence, the object-oriented application may store the objects within a relational database in which the state of the objects are stored as records in a relational database table and in which object attributes are mapped to columns within the relational database tables.
Databases have constraints that limit the operations that may be performed on the stored object representations within the database by an object-oriented application. For example, there are foreign-key constraints, or dependency constraints, in the relational database that ensure the integrity of the data. When a data representation of an object is deleted from the relational database, the deletion of the underlying database record must abide by the database constraints so that if there are any dependencies, the deletion must be handled accordingly. As another example, a database may have specific data field size limitations that prevent objects that exceed the size limit from being stored within the database.
Database constraints and data type size limits are some of the common exception cases that developers need to address in object models that store their data in databases. When the state of one or more objects are persisted into the database, the stored data must conform to those constraints. However, the object classes and their instances defined by an object model generally lack sufficient information about those database constraints and size limits because the knowledge of the database constraints and size limits is expressed outside of the domain of the object model, e.g., in the relational database schema definition if a relational database is used to store the state of the object model.
As a result, the clients of the object model cannot query the object model to learn about the constraints and size limits. When an object is stored in the database, the database may generate an error if a constraint or size limit is exceeded. The objects in an object model may be expected to handle the database errors at the time their state is stored, but because the objects lack any knowledge of appropriate policies to deal with those kind of errors, the errors are passed to the clients of the object model. It would be beneficial if the objects could handle these errors themselves in a well-behaved and consistent manner.
The clients of an object model would also benefit from objects having knowledge of predefined policies that should be adopted when some of the database constraints are violated or size limits are exceeded. For example, the semantics of certain attributes of an object may allow for the attributes to be truncated, such as those of a descriptive nature, while other attributes have to be stored intact to be meaningful.
Therefore, it would be advantageous to provide a method and system for allowing an object model to be aware of the database constraints and size limitations as well as capable of using semantic information about attributes to adopt policies for dealing with those constraints and limits.